package _2_Linkedlist;

import java.util.*;

public class A06_reversePrint {
    public int[] reversePrint(ListNode head) {
        List<Integer> res = new ArrayList<>();
        while (head !=null){
            res.add(head.val);
            head = head.next;
        }
        Collections.reverse(res);
        // int[] ints = Arrays.stream(resIntArr).mapToInt(i -> Integer.valueOf(i)).toArray();
        int[] arr2 = res.stream().mapToInt(Integer::valueOf).toArray();
        return arr2;
    }
    public int[] reversePrint2(ListNode head) {
        Stack<ListNode> stack = new Stack<ListNode>();
        ListNode temp = head;
        while (temp != null) {
            stack.push(temp);
            temp = temp.next;
        }
        int size = stack.size();
        int[] print = new int[size];
        for (int i = 0; i < size; i++) {
            print[i] = stack.pop().val;
        }
        return print;
    }

    public static void main(String[] args) {
        A06_reversePrint a06_reversePrint = new A06_reversePrint();
        ListNode listNode = new ListNode(3);
        ListNode listNode2 = new ListNode(4);
        listNode.next = listNode2;
        int[] ints = a06_reversePrint.reversePrint(listNode);

//        Stack<String> strings = new Stack<>();
//        strings.push("1");
//        strings.push("2");
//        strings.push("3");
//        strings.push("4");
//        int search = strings.search("1");
    }
}
